//
//  StartGameViewController.m
//  GameChooser
//
//  Created by LT-LT on 14-4-1.
//  Copyright (c) 2014年 moonwolf. All rights reserved.
//

#import "StartGameViewController.h"
#import "YouMiWall.h"
#import "YouMiPointsManager.h"
#import "GetCoinViewController.h"
#import "MoonGlobalTool.h"
#define GAME_NAME @"名将"
#define SIZE_X    self.view.bounds.size.height/2-50
#define SIZE_Y    self.view.bounds.size.height/2-50

#import "JoymengAdView.h"
@interface StartGameViewController ()
@property(nonatomic,strong)UILabel *coinNumLabel;

@end

@implementation StartGameViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title=GAME_NAME;
        // Custom initialization
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self refreshCoinNumber];
}
-(void)refreshCoinNumber
{
    [_coinNumLabel setText:[NSString stringWithFormat:@"%d",[MoonGlobalTool CoinNumber]]];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.userInteractionEnabled=YES;
    UIImageView *backImageview=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Back_image"]];
    backImageview.frame=CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width);
    [self.view addSubview:backImageview];
    [backImageview release];
    
    UIButton *startButton=[[UIButton alloc] initWithFrame:CGRectMake(SIZE_X, 200, 100, 40)];
   // [startButton setTitle:@"开始游戏" forState:UIControlStateNormal];
    [startButton setImage:[UIImage imageNamed:@"start_button"] forState:UIControlStateNormal];
    [startButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [startButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    [startButton addTarget:self action:@selector(startButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:startButton];
    [startButton release];
    

    UIButton *coinButton=[[UIButton alloc] initWithFrame:CGRectMake(SIZE_X, 250, 100, 40)];
    //[coinButton setTitle:@"获取游戏币" forState:UIControlStateNormal];
    [coinButton setImage:[UIImage imageNamed:@"getcoin_button"] forState:UIControlStateNormal];
    [coinButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [coinButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    [coinButton addTarget:self action:@selector(coinButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:coinButton];
    [coinButton release];
    
    
//    UIButton *moreButton=[[UIButton alloc] initWithFrame:CGRectMake(SIZE_X, 260, 100, 30)];
//    [moreButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [moreButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
//    [moreButton setTitle:@"更多游戏" forState:UIControlStateNormal];
//    [self.view addSubview:moreButton];
//    [moreButton release];
    

    UILabel *coinLabel =[[UILabel alloc] initWithFrame:CGRectMake(10, 290, 170, 30)];
    [coinLabel setText:@"你目前拥有游戏币："];
    [coinLabel setTextColor:[UIColor blackColor]];
    [self.view addSubview:coinLabel];
    [coinLabel release];
    
    _coinNumLabel =[[UILabel alloc] initWithFrame:CGRectMake(coinLabel.bounds.size.width+10, 290, 100, 30)];
    [_coinNumLabel setTextColor:[UIColor redColor]];
    [self.view addSubview:_coinNumLabel];

    joymengAdView *view=[[joymengAdView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)];
    __block UIViewController *blockController =self;
    __block joymengAdView *blockAdView=view;
    [view setCompletionBlock:^(BOOL success)
     {
         if (success) {
             blockAdView.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
             [blockController.view addSubview:blockAdView];
            
         }else
         {
             
         }
     }];
	// Do any additional setup after loading the view.
}

-(void)startButtonPressed:(id)sender
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"start" object:nil];
    [self performSelector:@selector(dismissSelf) withObject:nil afterDelay:2];
    
}

-(void)dismissSelf
{
    [self dismissViewControllerAnimated:YES completion:nil];
    
}
-(void)coinButtonPressed:(id)sender
{
    GetCoinViewController *getcoinVC=[[GetCoinViewController alloc] init];
    [self presentViewController:getcoinVC animated:YES completion:nil];
    [getcoinVC release];
}
-(void)dealloc
{
    [super dealloc];
    [_coinNumLabel release];
}
-(void)moreButtonPressed:(id)sender
{
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
